//
//  SectionToastView.m
//  iHome
//
//  Created by ma c on 2017/8/9.
//  Copyright © 2017年 mountec. All rights reserved.
//

#import "SectionToastView.h"

#define kToastWidth 80

@interface SectionToastView ()

@property (nonatomic,strong)UILabel *textLb;

@property (nonatomic,strong)UIVisualEffectView *visualView;

@end

@implementation SectionToastView

- (id)init{
    if (self = [super initWithFrame:CGRectMake(0, 0, kToastWidth, kToastWidth)]) {
        
        self.textLb = [[UILabel alloc] initWithFrame:self.bounds];
        self.textLb.textAlignment = NSTextAlignmentCenter;
        self.textLb.font = [UIFont systemFontOfSize:18];
        self.textLb.textColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor clearColor];
        self.visualView.bounds = self.bounds;
        [self addSubview:self.visualView];
        self.clipsToBounds = YES;
        [self addSubview:self.textLb];

        self.layer.cornerRadius = 5.0;
        
    }
    return self;
}

- (UIVisualEffectView *)visualView {
    if (!_visualView) {
        _visualView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
        _visualView.frame = CGRectMake(0, 0, kToastWidth, kToastWidth);
    }
    return _visualView;
}

- (void)show:(NSString *)msg{
    self.textLb.text = msg;
    if (self.superview == nil) {
        UIWindow *keywindow = [UIApplication sharedApplication].keyWindow;
        self.center = CGPointMake(keywindow.bounds.size.width/2.0, keywindow.bounds.size.height/2.0);
        [keywindow addSubview:self];
    }
    
}


- (void)dismiss {
    if (self.superview) {
        [self removeFromSuperview];
    }
}

@end
